package cn.szzsi._sys;

import cn.szzsi._admin.BaseAdminController;
import cn.szzsi.common.bean.SystemConfig;
import cn.szzsi.common.kit.CommonUtil;
import cn.szzsi.common.model.Friendlink;
import com.jfinal.core.Controller;
import com.jfinal.kit.PathKit;
import com.jfinal.kit.Ret;
import com.jfinal.kit.StrKit;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

import java.io.File;
import java.io.IOException;
import java.util.List;

/**
 * 商户后台类 - 友情链接 2016/9/26.
 */
public class FriendLinkController extends Controller {
    private Friendlink friendlink;
    private String shopId;

    // 添加
    public void add() {
        shopId=CommonUtil.PLATFROM_FLAG;
        setAttr("shopId",shopId);
        render("friend_link_input.html");
    }

    // 编辑
    public void edit() {
        shopId=CommonUtil.PLATFROM_FLAG;
        String id = getPara("id","");
        if(StrKit.notBlank(id)){
            setAttr("friendlink", Friendlink.dao.findById(id));
        }
        setAttr("shopId",shopId);
        render("friend_link_input.html");
    }

    // 列表
    public void list() {
        shopId=getAttr("shopId");
        render("friend_link_list.html");
    }
    //ajax list
    public void ajaxlist(){
        shopId=CommonUtil.PLATFROM_FLAG;
        List<Friendlink> lfl = Friendlink.dao.find("select * from mall_friendlink where uid = ? order by createDate desc",shopId);
        renderJson(lfl);
    }


    // 保存
    public void save(){
        shopId=CommonUtil.PLATFROM_FLAG;
        friendlink = getModel(Friendlink.class);
        friendlink.set("uid",shopId);
        renderJson(Ret.ok("info","添加成功").set("url","list"));
    }

    // 更新
    //@Before(BusinessFriendLinkValidator.class)
    public void update() {
        friendlink = getModel(Friendlink.class);
        renderJson(Ret.ok("info","修改成功").set("url","list"));
    }

    // 删除
    public void delete(){
        String id=getPara("id");
        if(Friendlink.dao.deleteById(id)){
            renderJson(Ret.ok());
        }else{
            renderJson(Ret.fail());

        }
    }
}
